package org.example.springbootpra1.demos.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.springbootpra1.demos.bean.ChargePlot;
import org.example.springbootpra1.demos.bean.ChargingPile;
import org.example.springbootpra1.demos.services.service.ChargePileService;
import org.example.springbootpra1.demos.services.service.ChargePlotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 充电站Controller
 *
 * @author zdcloud
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/pile")
public class ChargePileController
{
    @Autowired
    private ChargePileService chargePileService;

    @GetMapping("/list")
    public List<ChargingPile> list(ChargingPile chargingPile)
    {
        List<ChargingPile> list = chargePileService.list();
        return list;
    }


    @PostMapping("/pageList")
    public IPage<ChargingPile> pageList()
    {
        IPage<ChargingPile> list = chargePileService.getChargingPilePage();
        return list;
    }


    @PostMapping("/queryPageList")
    public IPage<ChargingPile> pageList(Page<ChargingPile> page, ChargingPile chargingPile)
    {
        QueryWrapper<ChargingPile> query = Wrappers.query();
        if (chargingPile.getPkName() != null && !chargingPile.getPkName().isEmpty()){
            query.like("pk_name",chargingPile.getPkName());
        }
        if (chargingPile.getId()!=null){
            query.eq("id",chargingPile.getId());
        }

        IPage<ChargingPile> list = chargePileService.getChargingPileQueryPage(page, query);
        return list;
    }
}